package com.hdax.dm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdax.dm.dto.OrderDto;
import com.hdax.dm.mappers.OrderMapper;
import com.hdax.dm.mapstructs.OrderDtoMapper;
import com.hdax.dm.order.DmOrder;
import com.hdax.dm.order.DmOrderLinkUser;
import com.hdax.dm.service.OrderService;
import com.hdax.dm.utils.response.CommonResponse;
import com.hdax.dm.utils.response.ResponseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, DmOrder> implements OrderService {

    @Autowired
    private OrderDtoMapper dtoMapper;

    @Override
    public CommonResponse<List<OrderDto>> orders(Long userid) {
        QueryWrapper wrapper = new QueryWrapper<>();
        wrapper.eq("userId",userid);
        List<DmOrder> orders = baseMapper.selectList(wrapper);
        List<OrderDto> dtoList = dtoMapper.orderDto(orders);

        return ResponseUtils.returnSuccess(dtoList);
    }

    @Override
    public List<DmOrder> orderNos(String no) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("orderNo",no);
        List<DmOrder> orders = list(wrapper);
        return orders;
    }

    @Override//删除订单
    public Boolean deleteOrder(String orderNo) {
        QueryWrapper wrapper = new QueryWrapper<>();
        wrapper.eq("orderNo",orderNo);
        return baseMapper.delete(wrapper)==1?true:false;
    }

    @Override//超时修改状态
    public Boolean orderType(String orderNO) {
        return baseMapper.orderType(orderNO);
    }

}
